import 'package:flutter/material.dart';
import 'package:wan_android_flutter/repository/Api.dart';

import '../../../repository/datas/knowledge_detail_list_model.dart';
import '../../../repository/datas/knowledge_list_model.dart';

class KnowledgeDetailTabviewModel with ChangeNotifier {
  List<Tab> tabs = [];

  void initData(List<KnowledgeChildren>? tabLists) {
    tabLists?.forEach((item) {
      tabs.add(Tab(
        text: item.name ?? "",
      ));
    });
  }

  List<KnowledgeDetailItem>? detailList = [];
  int pageCount = 0;
  int cid = 0;

  Future getDetailList(bool loadMore, String? cid,{ValueChanged<bool>? callBack}) async {
    if (loadMore) {
      pageCount++;
    } else {
      pageCount = 0;
      detailList?.clear();
    }
    await Api.instance().detailKnowledgeList("$pageCount", cid).then((list) {
      if (loadMore && (list == null || list.isEmpty) && pageCount > 0) {
        pageCount--;
        callBack?.call(loadMore);
        return;
      }
      detailList?.addAll(list ?? []);
      callBack?.call(loadMore);
      notifyListeners();
    });
  }
}
